import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/11 10:28
 * @description 动态规划
 */
public class Solution {
    public static void main(String[] args) {

    }
    int MOD = (int) 1e9 + 7;
    int N = 10005;
    int[][] cache;
    public int[] waysToFillArray(int[][] queries) {
        int n = queries.length;
        int[] ans = new int[n];
        // 备忘录
        cache = new int[N][N];
        for (int i = 0; i < n; i++) {
            int ni = queries[i][0], ki = queries[i][1];
            if (cache[ni][ki] == 0) {
                build(queries[i][0], queries[i][1]);
            }
            ans[i] = cache[ni][ki];
        }
        return ans;
    }

    /**
     * 构造长度为 n的正整数数组，满足所有元素乘积为k的方案数
     * @param n n
     * @param k k
     * @return int
     */
    public void build(int n, int k) {
        // dp[i][j]为长度为 i，构造乘积为 j的方案数， 优化长度维度
        int[] dp = new int[k + 1];
        for (int i = 1; i <= n ; i++) {
            for (int j = 1; j <= k; j++) {
                dp[j] = Math.max(dp[j], (int) (long) dp[j - i] * dp[i] % MOD);
            }
        }
        cache[n][k] = dp[k];
    }
}
